import os
from datetime import datetime
from os import path

from selenium.webdriver.android.webdriver import WebDriver

from apps.logger_config import logger
from apps.seleuinms import SNAP_IMAGE


def write_image(driver: WebDriver, file_path: str = None, file_name: str = None):
    if file_path is not None:
        dir_path = file_path
    else:
        asset_path = path.abspath(path.join(path.dirname(path.abspath(__file__)), '../../../assets'))
        name = file_name
        if name is None:
            name = str(datetime.now().timestamp())
        dir_path = path.join(asset_path, name + '.png')
    logger.info(SNAP_IMAGE, dir_path)
    driver.save_screenshot(r'' + dir_path)
